//
//  LZStaffManagerListCell.m
//  laziz_Merchant
//
//  Created by xbnzd on 17/3/1.
//  Copyright © 2017年 XBN. All rights reserved.
//

#import "LZStaffManagerListCell.h"
#import "LZStaffModel.h"

@interface LZStaffManagerListCell()
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UILabel *accountLabel;
@property (weak, nonatomic) IBOutlet UILabel *staffNameLabel;
@property (weak, nonatomic) IBOutlet UIView *promotionBgView;
@property (weak, nonatomic) IBOutlet UILabel *promotionLabel;
@property (weak, nonatomic) IBOutlet UIView *checkoutBgView;
@property (weak, nonatomic) IBOutlet UILabel *checkoutLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *promotionLabelCenterXToSuperViewCST;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *checkoutLabelCenterXToSuperViewCST;


@property (strong, nonatomic) NSIndexPath *indexPtemp;

@end

@implementation LZStaffManagerListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.promotionLabel.text = LZLocalizedString(@"staff_new_promotion", nil);
    self.checkoutLabel.text = LZLocalizedString(@"staff_customer_checkout", nil);
    self.bgView.layer.cornerRadius = 5;
    self.bgView.layer.masksToBounds = YES;
    self.promotionBgView.layer.cornerRadius = 9.0;
    self.promotionBgView.layer.masksToBounds = YES;
    self.checkoutBgView.layer.cornerRadius = 9.0;
    self.checkoutBgView.layer.masksToBounds = YES;
    
    self.promotionLabelCenterXToSuperViewCST.constant = 7;
    self.checkoutLabelCenterXToSuperViewCST.constant = 7;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    for (UIView *subView in self.subviews) {
        
        //只有滑动时才会创建 UITableViewCellDeleteConfirmationView
        if([subView isKindOfClass:NSClassFromString(@"UITableViewCellDeleteConfirmationView")]) {
            
            UIView *deleteConfirmationView = subView.subviews[0];
            //改背景颜色
            if (self.deleteImgView.hidden == YES) {
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    self.deleteImgView.hidden = NO;
                });
            }
            deleteConfirmationView.backgroundColor = [UIColor clearColor];
            self.deleteImgView.frame = CGRectMake(0, 0, 42, 42);
            [deleteConfirmationView addSubview:self.deleteImgView];
            
            self.deleteImgView.center = CGPointMake(deleteConfirmationView.center.x, deleteConfirmationView.center.y);
        }
    }
}

#pragma mark -
#pragma mark load data
- (void)loadCellContent:(LZStaffModel *)staffModel indexPath:(NSIndexPath *)indexPath
{
    self.indexPtemp = indexPath;
    
    self.accountLabel.text = staffModel.staffAccounts;
    self.staffNameLabel.text = staffModel.staffName;
    if (staffModel.role == 1) {
        self.checkoutBgView.backgroundColor = UIColorFromRGB(0x33a928, 1);
        self.promotionBgView.backgroundColor = UIColorFromRGB(0x999999, 1);
    }else if (staffModel.role == 2){
        self.promotionBgView.backgroundColor = UIColorFromRGB(0x33a928, 1);
        self.checkoutBgView.backgroundColor = UIColorFromRGB(0x999999, 1);
    }else if (staffModel.role == 3){
        self.promotionBgView.backgroundColor = UIColorFromRGB(0x33a928, 1);
        self.checkoutBgView.backgroundColor = UIColorFromRGB(0x33a928, 1);
    }else{
        self.promotionBgView.backgroundColor = UIColorFromRGB(0x999999, 1);
        self.checkoutBgView.backgroundColor = UIColorFromRGB(0x999999, 1);
    }
    
}

#pragma mark -
#pragma makr event
- (IBAction)editBtn:(id)sender {
    if (self.staffCellDelegate && [self.staffCellDelegate respondsToSelector:@selector(editStaffWithIndex:)]) {
        [self.staffCellDelegate editStaffWithIndex:self.indexPtemp];
    }
}


- (UIImageView *)deleteImgView
{
    if (_deleteImgView) {
        return _deleteImgView;
    }
    
    _deleteImgView = [[UIImageView alloc] init];
    _deleteImgView.contentMode = UIViewContentModeScaleAspectFit;
    _deleteImgView.image = [UIImage imageNamed:@"staff_delete"];
    
    return _deleteImgView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
